package com.fruit.auth.web.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.fruit.auth.model.Privilege;
import com.fruit.auth.service.PrivilegeService;
import com.fruit.web.action.util.BaseAction;
/**
 * 权限控制器
 * @author Administrator
 *
 */
@Controller
@Scope("prototype")
public class PrivilegeAction extends BaseAction<Privilege>
{

	private static final long serialVersionUID = -295844060845230160L;
	private Privilege privilege;
	@Resource
	private PrivilegeService privilegeService;

	@Override
	public Privilege getModel()
	{
		return privilege;
	}
	@Override
	public void prepare() throws Exception
	{
		privilege=new Privilege();
		privilege.setParent(new Privilege());
	}
	
	public String privileges()
	{
		List<Privilege> privileges=privilegeService.findTreePrivileges();
		renderJson(privileges);
		return NONE;
	}
	
	public String add()
	{
		privilegeService.savePrivilege(privilege);
		ajaxMsg.setSuccess(true);
		renderJson(ajaxMsg);
		return NONE;
	}
	
	public String delete()
	{
		privilegeService.deletePrivilege(privilege.getId());
		ajaxMsg.setSuccess(true);
		renderJson(ajaxMsg);
		return NONE;
	}
	
	public String update()
	{
		privilegeService.updatePrivilege(privilege);
		ajaxMsg.setSuccess(true);
		renderJson(ajaxMsg);
		return NONE;
	}
	
	public String find()
	{
		privilege=privilegeService.findPrivilege(privilege.getId());
		privilege.setParent(null);
		privilege.setChildren(null);
		ajaxMsg.setSuccess(true);
		ajaxMsg.setData(privilege);
		renderJson(ajaxMsg);
		return NONE;
	}
}
